import 'package:flutter/material.dart';

import 'pie_chart_view.dart';

// 圆饼图绘制,点击时实现动画, 使用ImplicitlyAnimatedWidget动画自定义
class PieChartPage extends StatefulWidget {
  @override
  _PieChartPageState createState() => _PieChartPageState();
}

class _PieChartPageState extends State<PieChartPage> {
  List<PieChartModel> listPieCharts = [
    PieChartModel(
      value: 35,
      name: 'A',
      color: Colors.blue,
      radius: 100,
    ),
    PieChartModel(
      value: 15,
      name: 'B',
      color: Colors.red,
      radius: 100,
    ),
    PieChartModel(
      value: 22,
      name: 'C',
      color: Colors.yellow,
      radius: 100,
    ),
    PieChartModel(
      value: 18,
      name: 'D',
      color: Colors.orange,
      radius: 100,
    ),
    PieChartModel(
      value: 39,
      name: 'F',
      color: Colors.green,
      radius: 100,
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Loading List'),
      ),
      body: Center(
        child: PieChartView(
          listPieCharts,
          onTap: (index) {
            listPieCharts.asMap().forEach((key, value) => value.radius = 100);
            if (index != -1) listPieCharts[index].radius = 110;
            setState(() {});
          },
        ),
      ),
    );
  }
}
